var fs = require('fs')
const nodeXlsx = require('node-xlsx')
const path = require('path');
console.log(path.resolve("."));
const java = require('java');
// const Buffer = require('buffer')

require('core-js/modules/es.promise');
require('core-js/modules/es.string.includes');
require('core-js/modules/es.object.assign');
require('core-js/modules/es.object.keys');
require('core-js/modules/es.symbol');
require('core-js/modules/es.symbol.async-iterator');
require('regenerator-runtime/runtime');

const ExcelJS = require('exceljs/dist/es5')


let files = fs.readdirSync('./execlFile', function (err, files) {
    if (err) {
        console.log('Error', err);
    } else {
        console.log('Result', files);
    }
});
let dataArr = []
let options = {}
let nameArr = []
files.forEach((it, index) => {
    let data = []
    console.log(it,'files,fles')
    // console.log(index)

    // if (index===0) {
    //     console.log(data[0].data[1])
    // }

    // if (nameArr[1].indexOf(data[0].data[1][23]) > -1) {
    //     console.log(true)
    // }
    // if (nameArr[1].length>7) {

    // }
    console.log(index)
    if (index === 0) {
        dataArr = nodeXlsx.parse(`./execlFile/${it}`)
    }
    // 4153
    if (index < 6000) {
        let data = nodeXlsx.parse(`./execlFile/${it}`)
        data[0].data.splice(0, 1)
        dataArr[0].data = dataArr[0].data.concat(data[0].data)
        // data[0].data.forEach((item, index) => {
        //     if (index != 0) {
        //         item.unshift(nameArr[0], nameArr[1], nameArr[2] === '1' ? '申请人,发明人' : '申请人')
        //     }
        // })

    }
})
console.log('finish')
// console.log(dataArr[0].data.length, '>>>>>>>>>>>>>>111111')
options = {
    sheetOptions: {
        '!cols': dataArr[0].data[0].map(item => ({ wch: 15 })),
        '!rows': dataArr[0].data.map((item, index) => { if (index == 0) { return { hpx: 40 } } else { return { hpx: 100 } } })
    }
}
console.log(2222222)
const buffer = nodeXlsx.build(dataArr, options);
console.log(333333)
fs.writeFileSync(path.join(__dirname, `./dist/data6001.xls`), Buffer.from(buffer));






